home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Produtividade / Software3 / Product4 / Data1.cab / _AD379BA235A642C881F915D54A7DD820 < prev    next >
Encoding:
Text File  |  2004-10-19  |  9.9 KB  |  347 lines

  1. /*******************************************************************/
  2. /*                                                                 */
  3. /*                      ADOBE CONFIDENTIAL                         */
  4. /*                   _ _ _ _ _ _ _ _ _ _ _ _ _                     */
  5. /*                                                                 */
  6. /* Copyright 2002 Adobe Systems Incorporated                       */
  7. /* All Rights Reserved.                                            */
  8. /*                                                                 */
  9. /* NOTICE:  All information contained herein is, and remains the   */
  10. /* property of Adobe Systems Incorporated and its suppliers, if    */
  11. /* any.  The intellectual and technical concepts contained         */
  12. /* herein are proprietary to Adobe Systems Incorporated and its    */
  13. /* suppliers and may be covered by U.S. and Foreign Patents,       */
  14. /* patents in process, and are protected by trade secret or        */
  15. /* copyright law.  Dissemination of this information or            */
  16. /* reproduction of this material is strictly forbidden unless      */
  17. /* prior written permission is obtained from Adobe Systems         */
  18. /* Incorporated.                                                   */
  19. /*                                                                 */
  20. /*******************************************************************/
  21.  
  22. /*
  23. **-----------------------------------------------------------------------------
  24. ** Effect File Variables - HLSLRefract.fx
  25. **-----------------------------------------------------------------------------
  26. */
  27.  
  28. uniform float4x4    gWorldViewProj : WorldViewProjection; // This matrix will be loaded by the application
  29. uniform float4x4    gWorldViewInverse;
  30. uniform float4x4    gWorld;
  31. uniform float4        gEyePosition;
  32. uniform float        gBumpAmount;
  33. uniform float        gRefractiveIndex;
  34. uniform float        gRippleParameter;
  35. uniform float        gDepth;
  36. texture                gVideoTexture;
  37. texture                gBumpTexture;
  38. const float            kModelDim = 4.0f;
  39.  
  40.  
  41.  
  42.  
  43. /*
  44. **-----------------------------------------
  45. **        Sampler States
  46. **-----------------------------------------
  47. */
  48. //incoming video texture
  49. sampler SamplerVideo = sampler_state
  50. {
  51.     Texture   = (gVideoTexture);
  52.     MipFilter = LINEAR;
  53.     MinFilter = LINEAR;
  54.     MagFilter = LINEAR;
  55.     BorderColor = 0x00000000;
  56.     AddressU = BORDER;
  57.     AddressV = BORDER;
  58.     
  59. };
  60.  
  61. sampler SamplerBump = sampler_state
  62. {
  63.     Texture   = (gBumpTexture);
  64.     MipFilter = LINEAR;
  65.     MinFilter = LINEAR;
  66.     MagFilter = LINEAR;
  67. };
  68.  
  69. /*
  70. **-----------------------------------------------------------------------------
  71. ** Vertex Definitions
  72. **-----------------------------------------------------------------------------
  73. ** APP_OUTPUT is the structure in which we receive the vertices from the application
  74. */
  75. struct APP_OUTPUT
  76. {
  77.     float3 mPosition    : POSITION;
  78.     float3 mNormal        : NORMAL;
  79.     float2 mTexCoord    : TEXCOORD0;
  80.     
  81. };
  82.  
  83. /* 
  84. ** Pixel Shader structure declaration
  85. */
  86.  
  87. struct REF_VS_OUTPUT
  88. {
  89.     float4 mPosition            :POSITION;
  90.     float2 mTexcoord            :TEXCOORD0;
  91.     float3 mPositionT            :TEXCOORD1;
  92.     float3 mIncidentVectorT        :TEXCOORD2;
  93.     float3 mBacktexS            :TEXCOORD3;
  94.     float3 mBacktexT            :TEXCOORD4;
  95. };
  96.  
  97. struct REF_PS_OUTPUT
  98. {
  99.     float4 mColor : COLOR;
  100. };
  101.  
  102. struct TEMP_OUT
  103. {
  104.     float4 mPosition : POSITION;
  105.     float3 mNormal     : NORMAL0;
  106.     float3 mTangent;
  107.     float3 mBinormal;
  108. };
  109.  
  110. /*
  111. **------------------------------------------------
  112. **        Ripple effect
  113. **------------------------------------------------
  114. */
  115. TEMP_OUT MakeRipple( float3 position, uniform float param )
  116. {
  117.     TEMP_OUT returnVertex;
  118.     float sinVal, dist = 0;
  119.     
  120.     dist = distance ( position, float3( 0.0, 0.0, 0.1) );
  121.  
  122.     sinVal = sin((dist+param)*25);
  123.     
  124.     returnVertex.mPosition = float4(position.x,
  125.                                 position.y, 
  126.                                 position.z,
  127.                                 1.0f );
  128.     
  129.     returnVertex.mTangent = normalize( float3( 1.0, 0, param*0.10*sinVal*position.x/dist) );
  130.     returnVertex.mBinormal= normalize( float3( 0, 1.0, param*0.10*sinVal*position.y/dist) );
  131.     returnVertex.mNormal = cross( returnVertex.mTangent, returnVertex.mBinormal );
  132.  
  133.     return returnVertex;
  134. }
  135.  
  136.  
  137. /*
  138. **------------------------------------------------
  139. **        my_refract function 
  140. **------------------------------------------------
  141. */
  142.  
  143. float3 my_refract( float3 I, float3 N, float eta )
  144. {
  145.     return I + eta*(-N-I);
  146. }
  147.  
  148.  
  149. /*
  150. **------------------------------------------------
  151. **        Glass vertex shader
  152. **------------------------------------------------
  153. */
  154. REF_VS_OUTPUT rect_vs( APP_OUTPUT IN )
  155. {
  156.     REF_VS_OUTPUT OUT;
  157.  
  158.     TEMP_OUT tempVtx = MakeRipple( IN.mPosition, gRippleParameter );
  159.     
  160.     // transform vertex position into homogenous clip-space
  161.     OUT.mPosition = mul(gWorldViewProj, (tempVtx.mPosition) );
  162.     
  163.     // copy texture coordinates
  164.     OUT.mTexcoord.xy = IN.mTexCoord.xy;
  165.     
  166.     float3x3 stspacemat = float3x3(tempVtx.mTangent,tempVtx.mBinormal,tempVtx.mNormal);
  167.     
  168.     //compute positon and normal in world space
  169.     float3 positionW = mul(gWorld,tempVtx.mPosition);
  170.         
  171.     //compute the incident vector(in world space)- and transform to texture space
  172.     float3 incidentVectorW = positionW - gEyePosition;
  173.     incidentVectorW = normalize(incidentVectorW);
  174.     OUT.mIncidentVectorT=mul(stspacemat,mul(gWorldViewInverse,incidentVectorW));
  175.     OUT.mIncidentVectorT = normalize( OUT.mIncidentVectorT );
  176.     
  177.     //carrying fwd the positionW in texturespace
  178.     OUT.mPositionT =mul(stspacemat,tempVtx.mPosition);
  179.     
  180.     OUT.mBacktexS = mul(stspacemat,float3(1.0f,0.0,0.0));
  181.     OUT.mBacktexT = mul(stspacemat,float3(0.0,1.0f,0.0));
  182.     
  183.     return OUT;
  184. }
  185.  
  186.  
  187. REF_VS_OUTPUT rect_vs_1_3( APP_OUTPUT IN )
  188. {
  189.     REF_VS_OUTPUT OUT;
  190.  
  191.     TEMP_OUT tempVtx = MakeRipple( IN.mPosition, gRippleParameter );
  192.     
  193.     // transform vertex position into homogenous clip-space
  194.     OUT.mPosition = mul(gWorldViewProj, (tempVtx.mPosition) );
  195.         
  196.     float3x3 stspacemat = float3x3(tempVtx.mTangent,tempVtx.mBinormal,tempVtx.mNormal);
  197.     
  198.     //compute positon and normal in world space
  199.     float3 positionW = mul(gWorld,tempVtx.mPosition);
  200.         
  201.     //compute the incident vector(in world space)- and transform to texture space
  202.     float3 incidentVectorW = positionW - gEyePosition;
  203.     incidentVectorW = normalize(incidentVectorW);
  204.     OUT.mIncidentVectorT=mul(stspacemat,mul(gWorldViewInverse,incidentVectorW));
  205.     OUT.mIncidentVectorT = normalize( OUT.mIncidentVectorT );
  206.     
  207.     //carrying fwd the positionW in texturespace
  208.     OUT.mPositionT =mul(stspacemat,tempVtx.mPosition);
  209.     
  210.     OUT.mBacktexS = mul(stspacemat,float3(1.0f,0.0,0.0));
  211.     OUT.mBacktexT = mul(stspacemat,float3(0.0,1.0f,0.0));
  212.     
  213.     float3 refractedVectorT =my_refract(OUT.mIncidentVectorT, float3(0.0, 0.0, 1.0), gRefractiveIndex );
  214.  
  215.     float3 pointOnBackTextureT;
  216.     pointOnBackTextureT = gDepth*refractedVectorT + OUT.mPositionT;
  217.  
  218.     OUT.mTexcoord.x = dot(OUT.mBacktexS, pointOnBackTextureT);
  219.     OUT.mTexcoord.y = dot(OUT.mBacktexT, pointOnBackTextureT);
  220.     
  221.     return OUT;
  222. }
  223.  
  224.  
  225. /*
  226. **------------------------------------------------
  227. **        Glass pixel shader 2.0
  228. **------------------------------------------------
  229. */
  230. REF_PS_OUTPUT rect_ps_2_0( REF_VS_OUTPUT IN )
  231. {
  232. REF_PS_OUTPUT OUT;
  233.     
  234.     //compute local normals - in texture (s&t) space
  235.     float3 localNormalT;
  236.     localNormalT = tex2D( SamplerBump, IN.mTexcoord ).xyz;
  237.     localNormalT = 2*(localNormalT - 0.5);
  238.     
  239.     localNormalT=lerp(float3(0.0f,0.0f,1.0f),localNormalT,gBumpAmount);
  240.     
  241.     //find the refracted vector in TextureSpace
  242.     float3 refractedVectorT =my_refract(IN.mIncidentVectorT, localNormalT, gRefractiveIndex );
  243.     
  244.     //locate intersection with back surface
  245.     float3 pointOnBackTextureT;
  246.     pointOnBackTextureT = gDepth*refractedVectorT + IN.mPositionT;
  247.     
  248.     float2 lookupPoint;
  249.     lookupPoint.x = dot(IN.mBacktexS, pointOnBackTextureT);
  250.     lookupPoint.y = dot(IN.mBacktexT, pointOnBackTextureT);
  251.     
  252.     OUT.mColor = tex2D( SamplerVideo,lookupPoint);
  253.     
  254.     return OUT;
  255. }
  256.  
  257.  
  258. /*
  259. **------------------------------------------------
  260. **        Glass pixel shader 1.4
  261. **------------------------------------------------
  262. */
  263. REF_PS_OUTPUT rect_ps_1_4( REF_VS_OUTPUT IN )
  264. {
  265.     REF_PS_OUTPUT OUT;
  266.     
  267.     //compute local normals - in texture (s&t) space
  268.     float3 localNormalT;
  269.     localNormalT = tex2D( SamplerBump, IN.mTexcoord ).xyz;
  270.     localNormalT = 2*(localNormalT - 0.5)*gBumpAmount; //normal is in s&t space
  271.     
  272.     //find the refracted vector in TextureSpace
  273.     float3 refractedVectorT =my_refract(IN.mIncidentVectorT, localNormalT, gRefractiveIndex );
  274.     
  275.     //locate intersection with back surface
  276.     float3 pointOnBackTextureT;
  277.     pointOnBackTextureT = gDepth*refractedVectorT + IN.mPositionT;
  278.     
  279.     float2 lookupPoint;
  280.     lookupPoint.x = dot(IN.mBacktexS, pointOnBackTextureT);
  281.     lookupPoint.y = dot(IN.mBacktexT, pointOnBackTextureT);
  282.     
  283.     OUT.mColor = tex2D( SamplerVideo, lookupPoint); 
  284.     
  285.     return OUT;
  286. }
  287.  
  288. REF_PS_OUTPUT rect_ps_1_3( REF_VS_OUTPUT IN )
  289. {
  290.     REF_PS_OUTPUT OUT;
  291.     
  292.     OUT.mColor = tex2D( SamplerVideo, IN.mTexcoord );
  293.     
  294.     return OUT;
  295. }
  296.  
  297.  
  298. /*
  299. **----------------------------------------------------------
  300. **        Technique with one pass [TODO] add pass for ps_1_4
  301. **----------------------------------------------------------
  302. */
  303.  
  304.  
  305. technique refract_2_0
  306. {
  307.     pass Pass0 //for the rectangular glass piece
  308.     {
  309.         Sampler[0] = (SamplerVideo); 
  310.         Sampler[1] = (SamplerBump);
  311.         
  312.         VertexShader = compile vs_2_0 rect_vs();
  313.         PixelShader  = compile ps_2_0 rect_ps_2_0();
  314.         
  315.     }
  316.     
  317. }
  318.  
  319.  
  320.  
  321. technique refract_1_4
  322. {
  323.     pass Pass0 //for the rectangular glass piece
  324.     {
  325.         Sampler[0] = (SamplerVideo); 
  326.         Sampler[1] = (SamplerBump);
  327.         
  328.         VertexShader = compile vs_1_1 rect_vs();
  329.         PixelShader  = compile ps_1_4 rect_ps_1_4();
  330.         
  331.     }
  332.     
  333. }
  334.  
  335. technique refract_1_3
  336. {
  337.     pass Pass0 //for the rectangular glass piece
  338.     {
  339.         Sampler[0] = (SamplerVideo); 
  340.     
  341.         VertexShader = compile vs_1_1 rect_vs_1_3();
  342.         PixelShader  = compile ps_1_3 rect_ps_1_3();
  343.         
  344.     }
  345.     
  346. }
  347.